package com.kdzy.lshy.socity_server.controller;

import com.kdzy.lshy.socity_server.service.FeedbackService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/feedback")
@CrossOrigin("*")
@Api(value = "FeedbackController", description = "意见反馈")
public class FeedbackController {

    private static final Logger logger = LoggerFactory.getLogger(WechartController.class);

    @Autowired
    FeedbackService feedbackService;

    /**
     * 添加意见反馈
     */

    @RequestMapping(value = "/saveFeedback", method = RequestMethod.POST)
    @ApiOperation(notes = "/saveFeedback", httpMethod = "POST", value = "保存用户反馈", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiResponses({

            @ApiResponse(code = 66, message = "数据添加成功"),
            @ApiResponse(code = 88, message = "参数为空"),
            @ApiResponse(code = 77, message = "数据库操作失败"),
            @ApiResponse(code = 98, message = "参数类型错误"),
            @ApiResponse(code = 99, message = "后台处理异常")
    })
    public Object saveFeedback(
        @ApiParam(
                required = true,
                name = "param",
                value = "{\n" +
                        " \"socity_id\": \"社区id\",\n" +
                        " \"dweller_id\": 居民ID,\n" +
                        " \"feed_title\": 反馈标题,\n" +
                        " \"feed_message\": 反馈内容,\n" +
                        " \"feed_photo\": 反馈图片地址,\n" +
                        " \"feed_name\": 反馈人姓名,\n" +
                        " \"stamp\": 时间戳,\n" +
                        " \"is_used\": 是否有效 0:有效 1:无效,\n" +
                        " \"version\": 版本 0:测试 1:生产,\n" +
                        " \"visit_plat\": 访问平台 0:网页 1:一体机 2:小程序 3:其他,\n" +
                        " \"visit_type\": 访问类型 0:测试 1:生产\n" +
                        "}")
        String param, HttpServletRequest request){
        logger.info("进入 保存意见反馈 saveFeedback()方法；入参param = " + param);
        System.out.println(System.currentTimeMillis());
        return feedbackService.saveFeedback(param,request);
    }


    /**
     * 条件查询
     * @param param
     * @param request
     * @return
     */
    @RequestMapping(value = "/selectFeedback", method = RequestMethod.POST)
    @ApiOperation(notes = "/selectFeedback", httpMethod = "POST", value = "查询用户反馈", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiResponses({
            @ApiResponse(code = 77, message = "数据库返回数据为空"),
            @ApiResponse(code = 88, message = "参数为空"),


    })
    public Object selectFaceback(
            @ApiParam(
                    required = true,
                    name = "param",
                    value = "{\n" +
                            " \"socity_id\": \"社区id\",\n" +
                            " \"dweller_id\": 居民ID,\n" +
                            " \"feed_title\": 反馈标题,\n" +
                            " \"feed_message\": 反馈内容,\n" +
                            " \"feed_photo\": 反馈图片地址,\n" +
                            " \"feed_name\": 反馈人姓名,\n" +
                            " \"stamp\": 时间戳,\n" +
                            " \"is_used\": 是否有效 0:有效 1:无效,\n" +
                            " \"version\": 版本 0:测试 1:生产,\n" +
                            " \"visit_plat\": 访问平台 0:网页 1:一体机 2:小程序 3:其他,\n" +
                            " \"visit_type\": 访问类型 0:测试 1:生产\n" +
                            " \"dweller_idcard\": 居民身份证\n" +
                            "}")
                    String param, HttpServletRequest request){
        logger.info("进入 查询用户反馈 selectFeedback()方法；入参param = " + param);
        return feedbackService.selectFeedback(param,request);
    }


}
